﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Web.Mvc;

namespace CTools.Controllers
{
    public class JsonResultHandleErrorAttribute : FilterAttribute, System.Web.Mvc.IExceptionFilter
    {
        public void OnException(ExceptionContext filterContext)
        {
            Common.Msg.DoResult<object> doResult = new Common.Msg.DoResult<object>();
            if (filterContext.ExceptionHandled == false)//判断是否已经处理过异常
            {
                doResult.Msg = filterContext.Exception.Message;
                doResult.EnumCode = Common.Msg.EnumCode.Error;
                filterContext.Result = new JsonResult() { Data = doResult };
                filterContext.ExceptionHandled = true;
            }
        }
    }
}